import IndexUtils from "@/utils/IndexUtils";
const header_tpl = require("./header_ejs.tpl")()

class Header_ejs extends HTMLElement {
    // 生命周期 - created
    constructor() {
        super();
        const shadow:ShadowRoot = this.attachShadow( { mode: 'closed' } );
        const templateElem:HTMLTemplateElement = <HTMLTemplateElement>IndexUtils.Instance.parseDom(header_tpl)
        const content:ParentNode = <ParentNode>templateElem.content.cloneNode(true);
        console.log(content)

        content.querySelector('img')!.setAttribute('src', this.getAttribute('image')!);
        content.querySelector('.container>.name')!.innerHTML = this.getAttribute('name')!;
        shadow.appendChild(content);
    }

    // 生命周期 - mounted
    connectedCallback () {
        console.log('connectedCallback被执行');
    }

    // 生命周期 - update
    attributeChangedCallback () {
        console.log('connectedCallback被执行');
    }

    // 生命周期 - destory
    disconnectedCallback() {
        console.log('被移出')
    }
}

export default Header_ejs